package com.yupi.yuoj.judege.codesandbox;

import com.yupi.yuoj.judege.codesandbox.impl.ExampleCodeSandboxImpl;
import com.yupi.yuoj.judege.codesandbox.impl.RemoteCodeSandboxImpl;
import com.yupi.yuoj.judege.codesandbox.impl.ThirdPartyCodeSandboxImpl;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Description 根据字符串参数创建 代码沙箱示例
 * @Author JFeng
 * @Date 2023/10/14
 */
@Component
public class CodeSandboxFactory {
    /**
     * 创建代码沙箱示例
     *
     * @param type 沙箱类型
     * @return
     */
    @Resource
    private Map<String,CodeSandbox> codeSandboxMap;

    public CodeSandbox newInstance(String type) {
        switch (type) {
            case "example":
                return codeSandboxMap.get("EXAMPLE");
            case "remote":
                return codeSandboxMap.get("REMOTE");
            case "thirdParty":
                return codeSandboxMap.get("thirdparty");
            default:
                return codeSandboxMap.get("EXAMPLE");
        }
    }
}
